<template>
  <div>
    <div
      class="wrapper-container "
      style="display: flex; flex-direction: column; width: 1711px"
    >
      <div class="search-container">
        <div class="search-container-left">
          <div class="search-container-item" style="margin-left: 20px">
            <span>学期：</span>
            <el-select
              v-model="semester"
              style="width: 90px"
              size="mini"
              placeholder="请选择"
              clearable
            >
              <el-option
                v-for="item in semesterList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              >
              </el-option>
            </el-select>
          </div>

          <div class="search-container-item" style="width: 25%">
            <span>起止时间：</span>
            <el-date-picker
            style="width:130px"
              v-model="startDate"
              type="date"
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd"
              placeholder="选择日期"
              prefix-icon="a"
            >
            </el-date-picker>
            --
            <el-date-picker
            style="width:130px"
              v-model="endDate"
              type="date"
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd"
              placeholder="选择日期"
              prefix-icon="a"
            >
            </el-date-picker>
          </div>

          <div class="search-button" @click="getKbapxstj">
            <img src="../../../../assets/assessment/icon-search.png" alt="" />
            <span>查询</span>
          </div>
          <div class="search-button" @click="resetAll" style="margin-left:15px">
            <!-- <img src="../../../../assets/assessment/icon-search.png" alt="" /> -->
            <span>重置</span>
          </div>
        </div>
      </div>
    </div>

    <div class="assessment-container">
      <div class="table-container">
        <el-table
          :data="tableData"
          border
          class="table-data"
          row-class-name="row-class"
          cell-class-name="cell-class"
          header-row-class-name="header-row-class"
          header-cell-class-name="header-cell-class"
          style="height: calc(100vh - 350px); overflow-y: auto"
        >
          <el-table-column prop="bx" label="部门" align="center">
          </el-table-column>
          <el-table-column prop="kcs" label="上课门次" align="center">
            <template slot-scope="scope">
              <span class="undeLine">{{ scope.row["kcs"] }}</span>
              <i
                class="el-icon-edit edit-icon"
                @click="setClassTimes(scope.row)"
              ></i>
            </template>
          </el-table-column>
          <el-table-column
            prop="yapxs"
            label="已安排学时"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="yfbxs"
            label="已发布学时"
            align="center"
          ></el-table-column>
          <el-table-column prop="jss" label="教员数" align="center">
            <template slot-scope="scope">
              <span class="undeLine">{{ scope.row["jss"] }}</span>
              <i
                class="el-icon-edit edit-icon"
                @click="selectTeachersNumber(scope.row)"
              ></i>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="bottom-block" style="display: block">
      <div class="text">
        当前共找到{{ total }}条记录,当前显示{{ startPage }}-{{ endPage }}条
      </div>
      <div class="export-button">
        <img src="../../../../assets/assessment/icon-export.png" alt="" />
        <!-- <span>导出Excel</span> -->
        <download-excel
          class="export-btn"
          :data="tableData"
          :fields="jsonFields"
          type="xls"
          name="课表安排学时统计.xls"
          style="color: #f3b815"
        >
          &ensp;导出Excel
        </download-excel>
      </div>
    </div>
    <div class="pagination-block">
      <el-pagination
        prev-text="上一页"
        next-text="下一页"
        :page-size="pageSize"
        layout="prev, pager, next, jumper"
        :total="total"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
      >
      </el-pagination>
    </div>
    </div>
  </div>
</template>

<script>
import { static_getKbapxstj,queryCommonXueqi, queryDefaultXueQi, termDetails } from "@/api/trainingManagement/place.js";
import ButtonItem from "@/components/ButtonItem.vue";

export default {
  components: {
    ButtonItem,
  },
  data() {
    return {
      total: 0, //总条数
      pageSize: 50, //条数
      startPage: 0, //开始条数
      endPage: 0, //结束条数
      currentPage: 1, //当前页数
      jsonFields: {
        部门: "bx",
        上课门次: "kcs",
        已安排学时: "yapxs",
        已发布学时: "yfbxs",
        教员数: "jss",
      },
      semester: "", //学期
      semesterName: "", //学期名称
      semesterList: [], //学期列表
      startDate: "2022-01-01", //开始日期
      endDate: "2022-12-31", //结束日期
      tableData: [],
    };
  },
  created() {},
  mounted() {
    this.getDefaultXueQi();
    this.queryCommonXueqi();
  },
  methods: {
    async getDefaultXueQi(){
      queryDefaultXueQi().then(res=>{
        if(res.data.code == 200){
          this.semester = res.data.data;
        }
      }).then(()=>{
        this.termDetails()
      })
    },
    termDetails(){
      termDetails(this.semester).then(res=>{
        if(res.data.code == 200){
          this.startDate = res.data.data.xqksrq
          this.endDate = res.data.data.xqjsrq
        }
      }).then(()=>{
        this.getKbapxstj()
      })
    },
    // 获取学期列表
    async queryCommonXueqi() {
      const res = await queryCommonXueqi();
      if (res.data.code == 200) {
        this.semesterList = res.data.data;
        this.semesterName = this.semesterList[0].name;
      }
    },
    async getKbapxstj() {
      var current = this.currentPage;
      var size = this.pageSize;
      var params = {
        startDate: this.startDate,
        endDate: this.endDate,
        xueqi: this.semester
      }
      const res = await static_getKbapxstj(params, current, size);
      if (res.data.code == 200) {
        this.tableData = res.data.data.records;
        this.total = res.data.data.total;
        var length = this.tableData.length;
        this.calculatePage(
          this.pageSize,
          res.data.data.current, length);
      }
    },
    resetAll(){
      this.startDate = '';
      this.endDate = '';
      this.semester = ''
    },
    // 计算开始和结束条数
    calculatePage(pageSize, current, length) {
      if (current == 1) {
        if (length != 0) {
          this.startPage = 1;
          this.endPage = length;
        }
      } else {
        this.startPage = pageSize * (current - 1) + 1;
        this.endPage = parseInt(this.startPage)  + parseInt(length) - 1;
      }
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getKbapxstj();
    },
    setClassTimes(row) {
      var semID = this.semester;
      var semList = this.semesterList.filter(item=> {
        item.id == semID
      })
      if (semList.length > 0) {
        this.semesterName = semList[0].name;
      }
      this.$router.push({
        path: "/admin/statistic/numberCourseDetails",
        query: {
          bx: row.bx,
          classTimes:row.kcs,
          start:this.startDate,
          end: this.endDate,
          semester: this.semester,
          semesterName: this.semesterName
        },
      });
    },
    selectTeachersNumber(row) {
      var semID = this.semester;
      var semList = this.semesterList.filter(item=> {
        item.id == semID
      })
      if (semList.length > 0) {
        this.semesterName = semList[0].name;
      }
        this.$router.push({
        path: "/admin/statistic/numberTeachers",
        query: {
          bx: row.bx,
          classTimes:row.jss,
          start:this.startDate,
          end: this.endDate,
          semester: this.semester,
          semesterName: this.semesterName
        },
      });
    },
  },
  computed: {}, //计算属性
};
</script>
<style lang="less" scoped>
@import "../../../../styles/supervision.less";
@import "../../../../styles/delayedExam.less";

/deep/ .table-container {
  .el-table td,
  .el-table th.is-leaf,
  .el-table--border,
  .el-table--group {
    border-color: #c7d7eb;
  }

  .el-table__header tr,
  .el-table__header th {
    padding: 0;
    height: 76px;
    background-color: #edf2f9;
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    line-height: 20px;
    color: #004ca7;
  }

  .el-table__body tr,
  .el-table__body td {
    padding: 0;
    height: 86px;
  }

  .wrapper-button {
    display: flex;
    flex-direction: column;
    align-items: center;

    > div {
      margin-bottom: 8px;
    }
  }
  .table-data {
    width: 100%;
    border: 0.8px solid #004ca7;
    /*border-radius: 9px;*/
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #004ca7;
  }
}

.wrapper-container .search-container .search-container-left {
  width: 100%;
  flex-wrap: wrap;
  .search-container-item {
    width: 12%;
    margin-right: 0px;
      > span {
        text-align: left;
      }
      display: flex;
      justify-content: space-evenly;
      margin-bottom: 20px;
      align-items: center;
      /deep/ .el-date-editor .el-input__inner {
        height: 28px;
      }
  }
}

/deep/.el-date-editor.el-input {
  width: 110px;
}
/deep/ .el-input--medium {
  width: 110px;
  .el-input__inner {
    height: 28px;
    width: 110px;
    padding: 0px 18px;
  }
}
/deep/ .el-table thead {
  color: #004ca7 !important;
}

.btn {
  margin-top: 271px;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 271px;
  .submit {
    width: 84px;
    height: 27px;
    line-height: 8px;
  }
}

.mar-lef-2 {
  margin-left: 20px;
}
.undeLine {
  text-decoration: underline;
  cursor: pointer;
}

.edit-icon {
  font-size: 16px;
  color: #02c86c;
  margin-left: 10px;
  cursor: pointer;
}

.lx-top-body {
  margin: 25px 10px;
  display: flex;
  justify-content: space-between;
  width: calc(100% - 20px);
}

.pagination-block {
  margin-top: 20px;
  display: flex;
  flex-direction: row;
  justify-content: center;
}


.assessment-container {
  width: calc(100% - 20px);
  .table-container {
     width: 100%;
     margin-top: 10px;
  }
}

</style>
